/**
 * Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.
 *
 * This library is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation; either version 2.1 of the License, or (at your option)
 * any later version.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 * details.
 */

package com.mad.bikepony.model;

import com.liferay.portal.kernel.bean.AutoEscapeBeanHandler;
import com.liferay.portal.kernel.exception.SystemException;
import com.liferay.portal.kernel.util.StringBundler;
import com.liferay.portal.model.BaseModel;
import com.liferay.portal.model.impl.BaseModelImpl;

import com.mad.bikepony.service.QuestionResponseLocalServiceUtil;

import java.io.Serializable;

import java.lang.reflect.Proxy;

import java.util.HashMap;
import java.util.Map;

/**
 * @author nicola
 */
public class QuestionResponseClp extends BaseModelImpl<QuestionResponse>
	implements QuestionResponse {
	public QuestionResponseClp() {
	}

	public Class<?> getModelClass() {
		return QuestionResponse.class;
	}

	public String getModelClassName() {
		return QuestionResponse.class.getName();
	}

	public long getPrimaryKey() {
		return _questionnaireId;
	}

	public void setPrimaryKey(long primaryKey) {
		setQuestionnaireId(primaryKey);
	}

	public Serializable getPrimaryKeyObj() {
		return new Long(_questionnaireId);
	}

	public void setPrimaryKeyObj(Serializable primaryKeyObj) {
		setPrimaryKey(((Long)primaryKeyObj).longValue());
	}

	@Override
	public Map<String, Object> getModelAttributes() {
		Map<String, Object> attributes = new HashMap<String, Object>();

		attributes.put("questionnaireId", getQuestionnaireId());
		attributes.put("questionId", getQuestionId());
		attributes.put("vote", getVote());

		return attributes;
	}

	@Override
	public void setModelAttributes(Map<String, Object> attributes) {
		Long questionnaireId = (Long)attributes.get("questionnaireId");

		if (questionnaireId != null) {
			setQuestionnaireId(questionnaireId);
		}

		Long questionId = (Long)attributes.get("questionId");

		if (questionId != null) {
			setQuestionId(questionId);
		}

		Integer vote = (Integer)attributes.get("vote");

		if (vote != null) {
			setVote(vote);
		}
	}

	public long getQuestionnaireId() {
		return _questionnaireId;
	}

	public void setQuestionnaireId(long questionnaireId) {
		_questionnaireId = questionnaireId;
	}

	public long getQuestionId() {
		return _questionId;
	}

	public void setQuestionId(long questionId) {
		_questionId = questionId;
	}

	public int getVote() {
		return _vote;
	}

	public void setVote(int vote) {
		_vote = vote;
	}

	public BaseModel<?> getQuestionResponseRemoteModel() {
		return _questionResponseRemoteModel;
	}

	public void setQuestionResponseRemoteModel(
		BaseModel<?> questionResponseRemoteModel) {
		_questionResponseRemoteModel = questionResponseRemoteModel;
	}

	public void persist() throws SystemException {
		if (this.isNew()) {
			QuestionResponseLocalServiceUtil.addQuestionResponse(this);
		}
		else {
			QuestionResponseLocalServiceUtil.updateQuestionResponse(this);
		}
	}

	@Override
	public QuestionResponse toEscapedModel() {
		return (QuestionResponse)Proxy.newProxyInstance(QuestionResponse.class.getClassLoader(),
			new Class[] { QuestionResponse.class },
			new AutoEscapeBeanHandler(this));
	}

	@Override
	public Object clone() {
		QuestionResponseClp clone = new QuestionResponseClp();

		clone.setQuestionnaireId(getQuestionnaireId());
		clone.setQuestionId(getQuestionId());
		clone.setVote(getVote());

		return clone;
	}

	public int compareTo(QuestionResponse questionResponse) {
		long primaryKey = questionResponse.getPrimaryKey();

		if (getPrimaryKey() < primaryKey) {
			return -1;
		}
		else if (getPrimaryKey() > primaryKey) {
			return 1;
		}
		else {
			return 0;
		}
	}

	@Override
	public boolean equals(Object obj) {
		if (obj == null) {
			return false;
		}

		QuestionResponseClp questionResponse = null;

		try {
			questionResponse = (QuestionResponseClp)obj;
		}
		catch (ClassCastException cce) {
			return false;
		}

		long primaryKey = questionResponse.getPrimaryKey();

		if (getPrimaryKey() == primaryKey) {
			return true;
		}
		else {
			return false;
		}
	}

	@Override
	public int hashCode() {
		return (int)getPrimaryKey();
	}

	@Override
	public String toString() {
		StringBundler sb = new StringBundler(7);

		sb.append("{questionnaireId=");
		sb.append(getQuestionnaireId());
		sb.append(", questionId=");
		sb.append(getQuestionId());
		sb.append(", vote=");
		sb.append(getVote());
		sb.append("}");

		return sb.toString();
	}

	public String toXmlString() {
		StringBundler sb = new StringBundler(13);

		sb.append("<model><model-name>");
		sb.append("com.mad.bikepony.model.QuestionResponse");
		sb.append("</model-name>");

		sb.append(
			"<column><column-name>questionnaireId</column-name><column-value><![CDATA[");
		sb.append(getQuestionnaireId());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>questionId</column-name><column-value><![CDATA[");
		sb.append(getQuestionId());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>vote</column-name><column-value><![CDATA[");
		sb.append(getVote());
		sb.append("]]></column-value></column>");

		sb.append("</model>");

		return sb.toString();
	}

	private long _questionnaireId;
	private long _questionId;
	private int _vote;
	private BaseModel<?> _questionResponseRemoteModel;
}